package cn.itsy.web.controller;

import cn.itsy.dao.LoginUserDao;
import cn.itsy.pojo.User;
import cn.itsy.pojo.Warninfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
@RequestMapping("loginuser")
public class LoginUserController {
    @Resource
    private LoginUserDao ld;

    @RequestMapping("list")
    public ModelAndView loginUserList(ModelAndView ml, String ename, String warninfo) {
        String sql = "select * from user u,warninfo w where u.id=w.user_id";
        String sql1 = "select * from dept where 1=1";
        if (ename != null && !ename.equals("")) {
            sql += " and w.ename like '%" + ename + "%' ";
        }
        if (warninfo != null && !warninfo.equals("")) {
            sql += " and w.warninfo like '%" + warninfo + "%' ";
        }
        List<Warninfo> ul = ld.UserAll(sql);
        ml.addObject("ul", ul);
        List<Warninfo> dl = ld.UserAll(sql1);
        ml.addObject("dl", dl);
        ml.setViewName("/LoginUser");
        return ml;
    }

    @RequestMapping("tiaotiao")
    public String updateid(String id) {
        String sql = "update warninfo set is_status='2' where id='" + id + "'";
        ld.updept(sql);
        return "redirect:list";
    }
}
